/**
 * uni boundingClientRect的 Promise 版本
 * @param selector 组件选择器
 * @param instance 父组件实例
 * @returns Promise<NodeRect>
 */
export function getBoundingClientRect(selector, instance) {
    return new Promise((resolve) => {
        uni
            .createSelectorQuery()
            .in(instance?.proxy)
            .select(selector)
            .boundingClientRect((data) => {
            resolve(data);
        })
            .exec();
    });
}
/**
 * 获取可使用窗口尺寸
 */
export function getWindowInfo() {
    if (uni.getWindowInfo) {
        return uni.getWindowInfo();
    }
    const info = uni.getSystemInfoSync();
    return {
        pixelRatio: info.pixelRatio,
        screenWidth: info.screenWidth,
        screenHeight: info.screenHeight,
        windowWidth: info.windowWidth,
        windowHeight: info.windowHeight,
        statusBarHeight: info.statusBarHeight || 0,
        windowTop: info.windowTop || 0,
        windowBottom: info.windowBottom || 0,
        safeArea: info.safeArea,
        safeAreaInsets: info.safeAreaInsets,
        screenTop: 0,
    };
}
/**
 * 获取可使用窗口尺寸、滚动信息
 */
export function getViewportScrollInfo() {
    return new Promise((resolve) => {
        uni
            .createSelectorQuery()
            .selectViewport()
            .scrollOffset((res) => {
            resolve(res);
        })
            .exec();
    });
}
export function toTouchEvent(event, windowTop = 0) {
    if (!('touches' in event)) {
        const touches = [
            {
                clientX: event.clientX,
                clientY: event.clientY - windowTop,
                pageY: event.pageY,
                pageX: event.pageX,
            },
        ];
        event.changedTouches = touches;
        event.touches = event.type === 'mouseup' ? [] : touches;
    }
    return event;
}
export function getNode(selector, instance) {
    return new Promise((resolve) => {
        uni
            .createSelectorQuery()
            .in(instance?.proxy)
            .select(selector)
            .node((res) => {
            resolve(res?.node);
        })
            .exec();
    });
}
